package com.qf.emp.dao.impl;

import com.qf.emp.dao.UserDao;
import com.qf.emp.entity.Profile;
import com.qf.emp.entity.Page;
import com.qf.emp.entity.User;
import com.qf.emp.utils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl implements UserDao{
    private QueryRunner queryRunner = new QueryRunner(DbUtils.getDataSource());
    @Override
    public User selectUser(String username) {
        String sql = "select * from user where username = ?;";
        try {
            return queryRunner.query(sql, new BeanHandler<User>(User.class), username);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }
    @Override
    public int insertUser(User user) {
        String sql = "insert into user values(?,?,?,?)";
        try {
            return queryRunner.update(sql, user.getUsername(), user.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
